home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d11
/
ev678dev.arc
/
DAC.DOC
< prev
next >
Wrap
Text File
|
1990-07-03
|
5KB
|
145 lines
-------------------------------------------------------------------------
| DAC.DOC |
| This document describes the process for loading the color |
| registers of the video DAC and a sample code fragment. |
-------------------------------------------------------------------------
The DAC is only enabled when an analog monitor is attached.
The VGA's Digital-to-Analog Converter (DAC) contains an internal color
lookup table to allow the user to select up to 256 colors from a palette of
262,144 possible colors. The color look-up table is composed of 256
18-bit color registers. Each register is subdivided into 3 6-bit entries,
where each entry is in the range 00h..3Fh. These three values specify the
red (R), green (G), and blue (B) intensities of the color register. If R=G=B,
the color register's output is a shade of gray.
-------------------------
| 00h | R | G | B |
| 01h | R | G | B |
| 02h | R | G | B |
| 03h | R | G | B |
| . | . | . | . |
| . | . | . | . |
| . | . | . | . |
| FEh | R | G | B |
| FFh | R | G | B |
-------------------------
For 256 color modes (IBM mode 13h, Everex Extended 256 color modes), all 256
color registers are active. For all other modes, you can select the paging
mode and page# using IBM standard BIOS functions AX = 101Ah and AX = 1013h.
The BIOS also provides functions for reading and writing the DAC color
registers (AX = 1012h and AX = 1017h). If you wish to program the DAC
directly, there are several steps to follow:
1) Wait for vertical retrace. (This is not entirely necessary, but if
you write to the DAC when a retrace is not active, you will get
snow on the screen.)
2) Index the color register you want.
3) Output the R, G, and B values, in order.
Note: After writing the three color values, the color register index
will auto-increment to the next color register. Also, you must insure
that there is a minimum 240 nanosecond delay between the output of each
color value. This can easily be accomplished in assembly language by
inserting a jmp short $+2 between each out instruction.
A vertical retrace can be detected by reading the CRTC Stat port. This
port has address 3?Ah, where ? is D for color modes and B for monochrome
modes. A simple means of determining which value to use is to read the
CRTC Addr port number from the BIOS data area at 0:463 (word). This value
will be either 3B4h or 3D4h. Bit 3 of the byte read from the CRTC Stat port
is 1 if a vertical retrace is active. If you wish to prevent snow on the
screen, and you have a large block of color registers to output, you may wish
to wait for the leading edge of the vertical retrace by first waiting for the
retrace bit to go to 0, then waiting for the retrace bit to go to 1. This
will insure the maximum amount of time for outputting the block of color
registers before the retrace ends.
The DAC Addr port number is 3C7h (W) for reading the DAC, and 3C8h (RW) for
writing to the DAC. The color values are written and read through port 3C9h
in the order of R, then G, then B.
To read back the values in the DAC, write the starting address to port
3C7h, then read successive triples from port 3C9h.
; ************************************************************************
; ************************************************************************
mSysCrtcAddr equ 463h ; Offset to CRTC address in BIOS data
rDacAddrW equ 3C8h ; DAC Address port (Write mode)
rDacData equ 3C9h ; DAC Data port
NumColors equ 8 ; Program 8 color registers
FirstReg equ 0 ; First register to program
ColorTable db 00h,00h,00h ; Increasing intensities of gray
db 08h,08h,08h
db 10h,10h,10h
db 18h,18h,18h
db 20h,20h,20h
db 28h,28h,28h
db 30h,30h,30h
db 38h,38h,38h
; Wait for leading edge of vertical retrace first, to prevent snow
xor cx,cx ; Maximum delay for waiting
mov ds,cx
mov dx,ds:[mSysCrtcAddr] ; Get CRTC Addr
add dx,6 ; Get CRTC Stat
Wait1:
in al,dx
test al,8h ; Check for retrace inactive
jz RetraceInactive
loop Wait1
; At this point a retrace is not occurring. Now wait for leading edge
; of next retrace.
RetraceInactive:
xor cx,cx ; Maximum delay for waiting
Wait2:
in al,dx
test al,8h ; Check for retrace active
jnz RetraceActive
loop Wait2
; A retrace should be just starting now, so set the DAC Write index
RetraceActive:
mov dx,rDacAddrW ; Get DAC write address
mov al,FirstReg ; First color register to program
out dx,al ; Set write index
jmp short $+2 ; Insure sufficient delay
; DAC index set. Now load up the color registers
mov dx,rDacData ; Get DAC data address
mov cx,NumColors ; Number of color registers to program
lea si,ColorTable ; ds:si -> color table to load
push cs
pop ds
ProgramDACLoop:
lodsb ; Get one Red color value
out dx,al ; Write it out
jmp short $+2 ; Insure sufficient delay
lodsb ; Get one Green color value
out dx,al ; Write it out
jmp short $+2 ; Insure sufficient delay
lodsb ; Get one Blue color value
out dx,al ; Write it out
loop ProgramDACLoop
; Color registers are now loaded
; ************************************************************************
; ************************************************************************